package com.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.web.servlet.bean.GameInfo;
import com.web.servlet.bean.PlatformGameBean;
import com.web.servlet.dao.DBConnect;
import com.web.servlet.dao.PlatformGameListConnect;
import com.web.servlet.manager.GameServerMananger;
/**
 * 3 获得游戏列表  list
 * @author davie.yu
 *
 */
public class PlatformGameListServlet extends HttpServlet {

	private static final long serialVersionUID = 7827128990374983025L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		
		PrintWriter out = response.getWriter();
		
		//游戏列表
		List<GameInfo> list = GameServerMananger.getGameInfoList();
		Document document = DocumentHelper.createDocument();
    	Element rootElement = document.addElement("GameList");
    	for(int i=0;i<list.size();i++)
    	{
    		if(1==list.get(i).getId()){
    			continue;
    		}
    		GameInfo info = list.get(i);
    		Element ListElement = rootElement.addElement("list");
        	Element idElement = ListElement.addElement("gid"); //游戏id
        	Element nameCnElement = ListElement.addElement("cn"); //游戏中文名
        	Element nameEnElement = ListElement.addElement("en"); //游戏英文名
        	Element gameIpElement = ListElement.addElement("ip"); //游戏ip
        	Element gamePortElement = ListElement.addElement("P");//游戏端口
        	Element gameVersionElement = ListElement.addElement("V");//游戏版本号
        	Element gameIconVersionElement = ListElement.addElement("icV");//游戏icon版本号
        	Element gameDownElement = ListElement.addElement("dUrl");//游戏下载url .zip
        	Element gameIconDownElement = ListElement.addElement("iDUrl"); //游戏图标下载 .zip
        	Element webUrlElement = ListElement.addElement("wUrl"); //web http
        	Element payElement = ListElement.addElement("pay"); //开房费用
        	Element visElement = ListElement.addElement("vis"); //是否显示
        	
        	/*idElement.setText(String.valueOf(list.get(i).getId()));
        	nameCnElement.setText(list.get(i).getName());
        	nameEnElement.setText(list.get(i).getName());
        	gameIpElement.setText("127.0.0.1");
        	gamePortElement.setText("9999");
        	gameVersionElement.setText(list.get(i).getGame_version());
        	gameIconVersionElement.setText(String.valueOf(list.get(i).getIcon_version()));//游戏icon版本号
        	gameDownElement.setText(list.get(i).getGame_url());
        	gameIconDownElement.setText(list.get(i).getIcon_url());//游戏图标下载 .zip
        	webUrlElement.setText(list.get(i).getGame_url());//web http
        	payElement.setText(list.get(i).getPay());//开房费用
        	visElement.setText(String.valueOf(list.get(i).getGame_status()));//是否显示
*/    	
        	idElement.setText(String.valueOf(info.getGame_id()));
        	nameCnElement.setText(info.getName());
        	nameEnElement.setText("paoDeKuai");
        	gameIpElement.setText(info.getGame_url());
        	gamePortElement.setText(info.getGame_url());
        	gameVersionElement.setText(info.getGame_version());
        	gameDownElement.setText(info.getGame_url());
        	gameIconVersionElement.setText(info.getIcon_version());//游戏icon版本号
        	gameIconDownElement.setText(info.getIcon_url());//游戏图标下载 .zip
        	webUrlElement.setText(info.getGame_url());//web http
        	payElement.setText("10");//开房费用  info.getPay()
        	visElement.setText("1");//是否显示
    	}
    	
    	out.print(document.asXML());
	    	
		out.flush();
		out.close();
	}


}
